package com.ffggffgfv.backend.config;

import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 支付宝配置类
 */
@Configuration
public class AlipayConfig {

    @Value("${alipay.appId}")
    private String appId;    @Value("${alipay.privateKey}")
    private String merchantPrivateKey;

    @Value("${alipay.alipayPublicKey}")
    private String alipayPublicKey;    @Value("${alipay.gatewayUrl}")
    private String serverUrl;

    @Value("${alipay.format}")
    private String format;

    @Value("${alipay.charset}")
    private String charset;    @Value("${alipay.signType}")
    private String signType;

    @Value("${alipay.notifyUrl}")
    private String notifyUrl;

    @Value("${alipay.returnUrl}")
    private String returnUrl;

    /**
     * 获取支付宝客户端
     *
     * @return AlipayClient
     */
    @Bean
    public AlipayClient alipayClient() {
        return new DefaultAlipayClient(
                serverUrl,    // 支付宝网关
                appId,        // 应用ID
                merchantPrivateKey,  // 商户私钥
                format,       // 格式
                charset,      // 编码
                alipayPublicKey,     // 支付宝公钥
                signType      // 签名类型
        );
    }    /**
     * 获取支付成功后的同步回调地址
     *
     * @return 同步回调地址
     */
    public String getReturnUrl() {
        return returnUrl;
    }

    /**
     * 获取支付成功后的异步通知地址
     *
     * @return 异步通知地址
     */
    public String getNotifyUrl() {
        return notifyUrl;
    }

    // Getter方法
    public String getAppId() {
        return appId;
    }

    public String getMerchantPrivateKey() {
        return merchantPrivateKey;
    }

    public String getAlipayPublicKey() {
        return alipayPublicKey;
    }    public String getServerUrl() {
        return serverUrl;
    }

    public String getFormat() {
        return format;
    }

    public String getCharset() {
        return charset;
    }

    public String getSignType() {
        return signType;
    }
}
